<template>
  <el-container class="main_con">
   <div class="filter_con ds_block nopt">
     <div class="button_area">
       <el-button type="primary" size="medium" @click="addHandle">新增sku</el-button>
     </div>
      <div class="filter_area">
        <el-input v-model="params.name" size="medium" class="serach_input mr_15 mt_15" placeholder="用户姓名"></el-input>
        <el-input v-model="params.mobile" size="medium" class="serach_input mr_15 mt_15" placeholder="手机号码"></el-input>
        <el-button @click="search" size="medium">搜索</el-button>
      </div>
    </div>
    <div class="list_con">
      <el-table @selection-change="SelectHadnle"  :data="list"
        element-loading-text="" fit highlight-current-row>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="nickname" label="昵称"></el-table-column>
        <el-table-column prop="mobile" label="联系号码"></el-table-column>
        <el-table-column prop="status_text" label="状态"></el-table-column>
        <el-table-column prop="create_time" label="创建时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
          <!--  <el-button type="text" @click="EditHandle(scope.row.id)">编辑</el-button> -->
            <el-button type="text" @click="EnableHandle(scope.row)">{{scope.row.status_text=='正常' ? '禁用' : '启用'}}</el-button>
            <el-button type="text" @click="handleClose(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer">
        <el-button size="medium">批量删除
        </el-button>
        <el-pagination @current-change="ChangeCurrent" class="pages" background layout="prev, pager, next" :total="total">
        </el-pagination>
      </div>
    </div>

    <el-dialog :title="type=='add'?'新增sku' :'编辑'" :visible.sync="drawer" destroy-on-close width="800px">
      <editsku @on-close="beClose" :id='id' :type="type"></editsku>
    </el-dialog>

  </el-container>
</template>

<script>
  import {
    getskulist,
  } from "@/api/shop/skulist"
  import Editsku from './components/Editsku'
   import {fitter_keyword}  from "@/utils/index"
  export default {
    data() {
      return {
        params: {
          name: "",
          mobile: "",
          begin_date: '',
          end_date: ''
        },
        paramsdf:{

        },
        page: 1,
        size: 10,
        total: 0,
        listLoading: true,
        list: [],
        drawer: false,
        direction: 'rtl',
        id: "",
        type: 'add',
        selectionData: []
      }
    },
    components: {
      Editsku
    },
    mounted() {
      // this.getlist()
    },
    filters:{
      filter_role(s,list){

     var d=  list.filter(a=>{
         return a.id==s
       })
       if(d.length>0){
         return d[0].name
       }else{
         return '没有该角色'
       }
      }
    },
    methods: {
      search(){
        this.paramsdf = fitter_keyword(this.params);
        this.getlist()
      },
      //启用，禁用
      EnableHandle(data) {
        let _this = this
        let status = Number(data.status_text != '正常')
        this.$confirm(status ? '确认启用？' : '确认禁用？')
       .then(_ => {
            let params = data
            delete params.status_text;
            params.status = status
            editadminuser(params).then(res => {
              _this.getlist()
            })
          })
          .catch(_ => {});

      },
      //选择
      SelectHadnle(selection) {
        this.selectionData = selection
      },
      //删除
      handleClose(id) {
        let _this = this
        this.$confirm('确认删除？')
          .then(_ => {
            let data = {
              id: id
            }
            deladminuser(data).then(res => {
              _this.getlist()
            })
          })
          .catch(_ => {});
      },

      //新增
      addHandle() {
        this.type = 'add';
        this.drawer = true;
        this.id = -1
      },
      //编辑
      EditHandle(id) {
        this.id = id
        this.type = 'edit'
        this.drawer = true
      },
      //编辑完成
      beClose() {
        this.drawer = false,
          this.getlist()
      },
      //获取列表
      getlist() {
        this.listLoading = true
        var data = this.params
        getuserlist(this.page, data).then(res => {
          var jsondata = res.msg;
          this.list = jsondata.data;
          this.total = jsondata.total
          // this.list = response.data.items
          this.listLoading = false
        })
      },
      //获取时间
      gettime(value) {
        this.params.begin_date = value[0];
        this.params.end_date = value[1]
      },
      //切换页码
      ChangeCurrent(page) {
        this.page = page;
        this.getlist()
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
